package com.innoking.docsys.doc.controller;

import com.alibaba.fastjson.JSONObject;
import com.innoking.docsys.doc.dao.cluster.ClusterCmsJudItemMapper;
import com.innoking.docsys.doc.dao.cluster.ClusterCmsJudVolumeMapper;
import com.innoking.docsys.doc.dto.CmsJudItem;
import com.innoking.docsys.doc.dto.CmsJudVolume;
import com.innoking.docsys.utils.JsonToOtherUtil;
import com.innoking.docsys.utils.OtherPojo;
import com.innoking.docsys.utils.ResultObjVO;
import com.innoking.docsys.utils.ResultUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CmsVolumeController
 * @Description 卷操作方法
 * @Author wr
 * @Date 2019/9/11 001115:07
 */
@RestController
@RequestMapping("/getVolItem")
public class CmsVolumeItemController {
    Logger logger= LoggerFactory.getLogger(CmsVolumeItemController.class);

    @Autowired
    private ClusterCmsJudItemMapper clusterCmsJudItemMapper;

    /**
     * 通过卷内件Id查询卷内件实体
     * itemId  卷内件Id
     * @return CmsJudVolume对象
     */
    @PostMapping("/cmsJudVolItemByitemId")
    @ResponseBody
    public ResultObjVO cmsJudVolItemByitemId(@RequestBody String data) {
        logger.info("***itemId查询卷信息");
        OtherPojo ob = JsonToOtherUtil.rtOtherString(data);
        String s = ob.getObj().toString();
        JSONObject jsonObject = JSONObject.parseObject(s);
        String id = jsonObject.get("itemId").toString();
        if(StringUtils.isBlank(id)){
            return ResultUtil.error("itemId不能为空");
        }
        CmsJudItem cmsJudItem = clusterCmsJudItemMapper.selectByPrimaryKey(Long.valueOf(id));
        if(cmsJudItem ==null){
            return ResultUtil.error("未查询到");
        }
        //String s1 = JSON.toJSON(classByFoodsId).toString();
        return ResultUtil.success(cmsJudItem);
    }


}
